#! /usr/bin/env python
"""
    这是启动一系列话题订阅节点的函数，由于硬件接口层要实现一系列话题的订阅，因此将各种订阅者封装成了一个类
"""
import rospy
from std_msgs.msg import String
from motion_parser.msg import car_cmd,arm_cmd
from hwThreadManager import HWThreadManager

class SubscriberManager():

    def __init__(self):
        #创建一系列的订阅者
        #sub = rospy.Subscriber("chatter",String,doMsg,queue_size=10)
        '''
        ManualInterfaceName: manual_cmd_parser
        ArmParserTopic: arm_parser_cmd
        CarParserTopic: car_parser_cmd
        ShootTopic: shoot_cmd
        '''
        #这是机械臂消息的订阅者 
        self.armSub = rospy.Subscriber(rospy.get_param("ArmParserTopic","arm_parser_cmd"),arm_cmd,self.updateArm,queue_size=10)
        self.carSub = rospy.Subscriber(rospy.get_param("CarParserTopic","car_parser_cmd"),car_cmd,self.updateCar,queue_size=10)
        self.shootSub = rospy.Subscriber(rospy.get_param("ShootTopic","shoot_cmd"),String,self.updateShoot,queue_size=10)
        #这些是机器人上锁/解锁信息的订阅者  LockTopic: lock_cmd
        self.lockSub = rospy.Subscriber(rospy.get_param("LockTopic","lock_cmd"),String,self.updateLock,queue_size=10)
        print("load hwManager...")
        #这是线程的管理类，该类提供了一系列接口用于处理输入的信息
        self.threadManager = HWThreadManager()


    def updateArm(self,cmd):
        #这里将信息写入队列
        self.threadManager.updateArm(cmd)

    def updateCar(self,cmd):
        #这里将信息写入队列
        self.threadManager.updateCar(cmd)

    def updateShoot(self,cmd):
        self.threadManager.updateShoot(cmd)

    def updateLock(self,cmd):
        self.threadManager.updateLock(cmd)


    



